<template>
	<view>
		<view class="shichi" :style="{height:wh+'px'}">
			<view class="yiju">
				一句名言
			</view>
			<view class="name">
				{{mingyan.name}}
			</view>
			<view class="from">
				{{mingyan.from}}
			</view>
			<view class="new" @click="next">下一首</view>
			<view class="time">
				<my-time></my-time>
			</view>
			
		</view>
	</view>
</template>
<script>
	import {
		mapMutations,
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				//一句名言	
				mingyan: [],
				//可用高度
				wh: 0,
				//时间
				time: [],
				//定时器
				timer: null
			};
		},
		//页面加载
		onLoad() {
			//一句名言
			this.getmingyan()
			// 获取当前系统的信息
			const sysInfo = uni.getWindowInfo()
			// 可用高度 = 屏幕高度 - navigationBar高度 - tabBar高度 - 自定义的search组件高度
			this.wh = sysInfo.windowHeight
		},
		computed: {
		     ...mapState('m_user',['redirectInfo','token'])
		},
		methods: {
			...mapMutations('m_user',['updateRedirectInfo']),
			//获取名言
			async getmingyan() {
				const res = await uni.$http.get('/api/sentences', this.querobj)
				if (res.data.code !== 200) return uni.$showMsg(res.data.message)
				this.mingyan = res.data.result
			},
			//下一首
			next() {
				//检测用户是否登录
				if(!this.token) return this.delayNavigate()
				this.getmingyan()
			},
			// 导航到my页面
			delayNavigate(){
				uni.switchTab({
					url: '/pages/my/my',
					// 页面跳转成功之后的回调函数
					success: () => {
						// 调用 vuex 的 updateRedirectInfo 方法，把跳转信息存储到 Store 中
						this.updateRedirectInfo({
							// 跳转的方式
							openType: 'switchTab',
							// 从哪个页面跳转过去的
							from: '/pages/sort/sort'
						})
					}
				})
			},
		}

	}
</script>
<style lang="scss">
	.shichi {
		position: relative;
		width: 100%;
		background-size: cover;
		background-repeat: no-repeat;
		background-position: -200px 0px;
		background-image: url(https://img0.baidu.com/it/u=3023663513,3259674012&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=400);

		.name {
			position: absolute;
			left: 20%;
			top: 51%;
			width: 300px;
			font-weight: bold;
			font-size: 20px;
			font-family: 'Courier New', Courier, monospace;

		}

		.from {

			position: absolute;
			left: 45%;
			top: 45%;
			width: 190px;
			font-size: 13px;
		}

		.yiju {
			color: #8a8b8b;
			position: absolute;
			left: 30%;
			font-weight: bold;
			font-size: 40px;
			top: 30%;
			font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
		}

		.new {
			top: 20%;
			left: 7%;
			position: absolute;
			width: 60px;
			background-color: rgba(0, 0, 0, .1);
			height: 40px;
			font-size: 15px;
			text-align: center;
			line-height: 40px;
			border-radius: 10px;
			color: #8a8b8b;
			font-weight: bold;
		}
		.time{
			left: 66%;
			top: 20%;
			font-weight: bold;
			position: absolute;
			width: 100px;
			height: 40px;
			background-color: red;
			background-color: rgba(0, 0, 0, .1);
			text-align: center;
			line-height: 40px;
			border-radius: 10px;
			color: #8a8b8b;
		}

	}
</style>
